package com.daniu101.productbargan.controller;


import com.daniu101.productbargan.model.Admin;
import com.daniu101.productbargan.model.AdminVo;
import com.daniu101.productbargan.service.IAdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping(value = "admin")
public class AdminController {


    @Autowired
    private IAdminService adminService;
    // 跳入到管理员 初始化界面
    @RequestMapping(value = "/admininitview",method = RequestMethod.GET)
    public String admininitview(){
        return "admininit";
    }
    //超级管理员初始化
    @ResponseBody
    @RequestMapping(value = "/admininit",method = RequestMethod.POST)
    public String admininit(AdminVo adminVo){

        return adminService.inAdmin(adminVo);
    }

    //显示管理员信息

    @RequestMapping(value = "/admininfo",method = RequestMethod.GET)
    public ModelAndView admininfo(String id){

        Admin admin = adminService.getAdminById(id);
        ModelAndView mav = new ModelAndView();
        mav.setViewName("admininfo");
        mav.addObject("admin",admin);
        return mav;
    }
    // 超级管理员的个数，是否需要初始化
    @ResponseBody
    @RequestMapping(value = "/admincheck",method = RequestMethod.POST)
    public String admininit(){
        return "adminService.getAdmins";
    }
    // 手机or邮箱 验证码登录
    @ResponseBody
    @RequestMapping(value = "/loginvercode", method = RequestMethod.POST)
    public String loginVercode(AdminVo adminVo) {
        return adminService.loginVercode(adminVo);
    }
    // 手机or邮箱 密码登录
    @ResponseBody
    @RequestMapping(value = "/loginpassword", method = RequestMethod.POST)
    public String loginPassword(AdminVo adminVo) {
        return adminService.loginPassword(adminVo);
    }

    // 超级管理员更新
    @ResponseBody
    @RequestMapping(value = "/adminupdate", method = RequestMethod.POST)
    public String adminUpdate(Admin admin) {
        return adminService.updateAdmin(admin);
    }



}
